package com.xidata.dict.demo.service;

import com.xidata.dict.demo.db.MenuItem;
import com.xidata.dict.model.CodeLookupNotFoundStrategy;
import com.xidata.dict.service.CodeMainLanguageService;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Component
public class CodeMainLanguageServiceImpl implements CodeMainLanguageService {
    @Override
    public String getCodeText(String codeType, String code) {

        List<MenuItem> list = new ArrayList<>();
        list.add(new MenuItem("main", "主菜单"));
        list.add(new MenuItem("shop", "店铺"));
        list.add(new MenuItem("product", "商品"));


        Optional<MenuItem> any = list.stream().filter(item -> item.getCode().equals(code)).findAny();
        return any.orElse(new MenuItem()).getName();
    }

    @Override
    public String getMainLanguage() {
        return "zh";
    }

    @Override
    public CodeLookupNotFoundStrategy getStrategy() {
        return CodeLookupNotFoundStrategy.ONLINE_TRANSLATE;
    }
}
